package videoCourse.sort;

import java.util.Arrays;

public class MyQuickSort {
    public static void main(String[] args) {
        int[] nums = new int[]{3, 4, 6, 7, 2, 7, 2, 8, 0, 9, 1, 31, 25, 14, 14};
        quickSort(nums, 0, nums.length - 1);
        System.out.println(Arrays.toString(nums));
    }

//    public static  void quickSort(int[] arr,int begin,int end) {
//        if(begin < end){
//            int low=begin,high=end;
//            int target = arr[low];
//            while(low < high){
//                while(low < high && arr[high] >= target){
//                    high--;
//                }
//                arr[low] = arr[high];
//                while(low < high && arr[low] <= target){
//                    low++;
//                }
//                arr[high] = arr[low];
//            }
//            arr[low] = target;
//            quickSort(arr,begin,low);
//            quickSort(arr,low+1,end);
//        }
//    }

    public static void quickSort(int[] arr,int start, int end) {
        if (start < end) {
            int low = start;
            int high = end;
            int target = arr[low];
            while(low < high){

                while (arr[high] >= target && low < high) {
                    high--;
                }
                arr[low] = arr[high];
                while (arr[low] <= target && low < high) {
                    low++;
                }
                arr[high] = arr[low];
            }

            arr[low] = target;

            quickSort(arr,start,low);
            quickSort(arr,low+1,end);
        }
    }
}
